package com.llt.ai;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.ai.reader.TextReader;
import org.springframework.ai.transformer.splitter.TokenTextSplitter;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.Resource;



/**
 * @author LLT
 */
@SpringBootApplication
@MapperScan("com.llt.ai.mapper")
public class AiApplication {
    public static void main(String[] args) {
        SpringApplication.run(AiApplication.class, args);
    }

    @Bean
    CommandLineRunner commandLineRunner(VectorStore vectorStore, @Value("classpath:rag/terms-of-service.txt") Resource resource) {
        return args -> {
            // 3. 写入 + 向量化
            vectorStore.write(
                    // 2. 转换
                    new TokenTextSplitter().transform(
                            // 1. 读取
                            new TextReader(resource).read()
                    )
            );
        };
    }
}
